package com.yugao.fintech.libra.system;

import com.alibaba.cloud.nacos.NacosServiceAutoConfiguration;
import com.yugao.fintech.libra.common.module.auth.LoginUser;
import com.yugao.fintech.libra.common.module.config.ConfigInfo;
import com.yugao.fintech.libra.system.model.entity.SysUser;
import com.yugao.fintech.libra.system.model.rqrs.accesskey.AccessKeyResp;
import com.yugao.fintech.libra.system.model.rqrs.log.LoginUserGetReq;
import com.yugao.fintech.libra.system.model.rqrs.log.OperateLogSaveReq;
import com.yugao.fintech.libra.system.model.rqrs.tenant.TenantSaveReq;
import com.yugao.fintech.libra.system.model.rqrs.tenant.TenantUpdateReq;
import com.yugao.fintech.libra.system.model.rqrs.user.LoginUserDeleteReq;
import com.yugao.fintech.libra.system.model.rqrs.user.UserBasePageReq;
import com.yugao.fintech.libra.system.model.rqrs.user.UserResp;
import com.yugao.fintech.libra.system.model.rqrs.user.UserSaveReq;
import com.yugao.fintech.meheco.core.domain.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 用户服务降级处理
 */
@Slf4j
@Lazy
@Component
@ConditionalOnClass({FeignAutoConfiguration.class, NacosServiceAutoConfiguration.class})
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
public class RemoteSystemFallbackFactory implements FallbackFactory<RemoteSystemService> {

    @Override
    public RemoteSystemService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteSystemService() {
            @Override
            public ResultVO<AccessKeyResp> getAccessKeyBySecretId(String secretId) {
                return null;
            }

            @Override
            public ResultVO<AccessKeyResp> getAccessKeyById(Long id) {
                return null;
            }

            @Override
            public ResultVO<Boolean> saveOperateLog(OperateLogSaveReq req) {
                return null;
            }

            @Override
            public ResultVO<LoginUser> getLoginUser(LoginUserGetReq req) {
                return null;
            }

            @Override
            public ResultVO<Long> saveUser(UserSaveReq req) {
                return null;
            }

            @Override
            public ResultVO<?> removeUserById(Long userId) {
                return null;
            }

            @Override
            public ResultVO<List<UserResp>> listUser(UserBasePageReq query) {
                return null;
            }

            @Override
            public ResultVO<UserResp> getUserById(Long userId) {
                return null;
            }

            @Override
            public ResultVO<?> deleteLoginUser(LoginUserDeleteReq req) {
                return null;
            }

            @Override
            public ResultVO<List<UserResp>> listUserByIds(List<Long> userIds) {
                return null;
            }

            @Override
            public ResultVO<SysUser> getUserByAccount(String account) {
                return null;
            }

            @Override
            public ResultVO<Long> saveTenant(TenantSaveReq req) {
                return null;
            }

            @Override
            public ResultVO<?> deleteTenant(Long tenantId) {
                return null;
            }

            @Override
            public ResultVO<?> updateTenant(TenantUpdateReq req) {
                return null;
            }

            @Override
            public ResultVO<ConfigInfo> getUseConfig(String configDefine) {
                return null;
            }

            @Override
            public ResultVO<Map<String, List<String>>> listAssignRoleUrl(List<Long> roleIds) {
                return null;
            }
        };
    }
}
